package com.huawei.appmarket.service.pay.purchase;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.fragment.app.FragmentActivity;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.appzone.view.widget.AppZoneListView;
import com.huawei.appmarket.service.appzone.view.widget.NoDataView;
import com.huawei.appmarket.service.pay.purchase.view.AppTracesListFragmentProtocol;
import com.huawei.appmarket.service.pay.purchase.view.AppTracesListFragmentProtocol.Request;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.Iterator;
import java.util.List;
import o.cdb;
import o.cdg;
import o.cfv;
import o.cia;
import o.cih;
import o.BaseRequest;
import o.Logger;
import o.ContentManager;
import o.ecu;
import o.ecw;
import o.ecy;
import o.CollectCheck;
import o.ewm.h;
import o.ewm.j;
import o.ll;

public abstract class AppZoneListFragment<T extends AppListFragmentProtocol> extends AppListFragment<T> {
    private d ʹ = new d();
    protected NoDataView ˊ;
    private boolean ॱॱ = true;
    private final BroadcastReceiver ᐝ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ AppZoneListFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(intent.getAction())) {
                String stringExtra = intent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID");
                String stringExtra2 = intent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID");
                String stringExtra3 = intent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING");
                String stringExtra4 = intent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT");
                Logger.ˏ("AppZoneListFragment", "appId=" + stringExtra + ",commentId=" + stringExtra2 + ",rating=" + stringExtra3);
                this.ˊ.ˊ(stringExtra, stringExtra2, stringExtra3, stringExtra4);
            }
        }
    };
    private e ﾞ = new e();
    private boolean ﾟ = false;

    class d {
        final /* synthetic */ AppZoneListFragment ˊ;

        private d(AppZoneListFragment appZoneListFragment) {
            this.ˊ = appZoneListFragment;
        }

        public boolean ˎ() {
            try {
                AppTracesListFragmentProtocol appTracesListFragmentProtocol = (AppTracesListFragmentProtocol) this.ˊ.ˆ();
                if (appTracesListFragmentProtocol != null && appTracesListFragmentProtocol.ॱ() != null) {
                    return ((Request) appTracesListFragmentProtocol.ॱ()).ˎˎ();
                }
                Logger.ˎ("AppZoneListFragment", "oCreate appZoneEditListFragmentProtocol is null or request is null!");
                return false;
            } catch (Exception e) {
                return false;
            }
        }
    }

    class e {
        final /* synthetic */ AppZoneListFragment ˎ;

        private e(AppZoneListFragment appZoneListFragment) {
            this.ˎ = appZoneListFragment;
        }

        public void ˎ(TaskFragment taskFragment, b bVar) {
            BaseRequest o_cvu = bVar.ˊ;
            ResponseBean responseBean = bVar.ˋ;
            if ((o_cvu instanceof cfv) && (responseBean instanceof DetailResponse)) {
                Logger.ˎ("AppZoneListFragment", "OnCompleted,fragID:" + this.ˎ.ʼᐝ + ", reqcmd:" + o_cvu.getMethod_() + ",pagenum:" + this.ˎ.ˏ + ",type:" + responseBean.getResponseType());
                this.ˎ.ᶫ = System.currentTimeMillis();
                if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                    if (!(this.ˎ.ʼʻ() || this.ˎ.ॱˌ == null)) {
                        this.ˎ.ॱˌ.onEvent(0);
                        this.ˎ.ˋॱ(true);
                        this.ˎ.ॱˌ = null;
                    }
                    this.ˎ.ॱˋ(true);
                    ˎ(responseBean, this.ˎ.ʹ.ˎ());
                    this.ˎ.ॱꜞ.ॱ(this.ˎ.י, (cfv) o_cvu, (DetailResponse) responseBean, false);
                    this.ˎ.י.ͺ();
                    if (this.ˎ.ˏ == 1) {
                        this.ˎ.ͺˎ.setSelection(0);
                    }
                    this.ˎ.ˏ = this.ˎ.ˏ + 1;
                    int ˊॱ = this.ˎ.י.ˊॱ();
                    if (this.ˎ.ᐧॱ != null) {
                        this.ˎ.ᐧॱ.ˋ(this.ˎ.ʼᐝ, this.ˎ.י);
                    }
                    if (responseBean instanceof DetailResponse) {
                        this.ˎ.ʼ(((DetailResponse) responseBean).ʿ());
                    }
                    ˏ(ˊॱ);
                    FragmentActivity ॱˋ = this.ˎ.ॱˋ();
                    if (ॱˋ instanceof ecy) {
                        ((ecy) ॱˋ).ˏ();
                        return;
                    }
                    return;
                }
                ˏ(o_cvu, responseBean);
                return;
            }
            Logger.e("AppZoneListFragment", "onResponse, req not instanceof DetailRequest or res not instanceof DetailResponse");
        }

        private void ˏ(int i) {
            if (this.ˎ.י.ᐝ() || i != 0) {
                if (this.ˎ.ʹ.ˎ() && i == 0) {
                    this.ˎ.ʿˊ();
                }
                this.ˎ.ˊʻ();
                return;
            }
            this.ˎ.ٴ();
        }

        private void ˏ(BaseRequest o_cvu, ResponseBean responseBean) {
            if (!(o_cvu instanceof cfv)) {
                ॱ(responseBean);
            } else if (((cfv) o_cvu).ˏ() == 1) {
                this.ˎ.ॱˋ(true);
                ॱ(responseBean);
            } else {
                ॱ(responseBean);
            }
        }

        private ResponseBean ˎ(ResponseBean responseBean, boolean z) {
            DetailResponse detailResponse = (DetailResponse) responseBean;
            List<LayoutData> ᐝॱ = detailResponse.ᐝॱ();
            if (!CollectCheck.isEmpty(ᐝॱ)) {
                ecu ˋ = ecw.ˊ().ˋ();
                for (LayoutData ˋ2 : ᐝॱ) {
                    List ˋ3 = ˋ2.ˋ();
                    if (ˋ3 == null || ˋ3.isEmpty()) {
                        break;
                    }
                    Iterator it = ˋ3.iterator();
                    while (it.hasNext()) {
                        CardBean cardBean = (CardBean) it.next();
                        Object ॱـ = cardBean.ॱـ();
                        if ((z && !TextUtils.isEmpty(ॱـ) && ((cdg) cdb.ॱ(cdg.class)).ॱॱ(ॱـ)) || ˋ.ˋ(cardBean)) {
                            it.remove();
                        }
                    }
                }
            }
            return detailResponse;
        }

        private void ॱ(ResponseBean responseBean) {
            this.ˎ.ˊʻ();
            if (this.ˎ.ॱˌ != null) {
                if (responseBean.getRtnCode_() != 0) {
                    this.ˎ.ॱˋ(false);
                    this.ˎ.ﾟ = true;
                    this.ˎ.ॱˌ.onEvent(1);
                } else {
                    this.ˎ.ॱˌ.onEvent(responseBean.getResponseCode());
                }
            }
            this.ˎ.ͺˎ.ॱˊ();
        }
    }

    protected abstract void ˊ(String str, String str2, String str3, String str4);

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View ˋ = super.ˋ(layoutInflater, viewGroup, bundle);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentAdded");
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.ᐝ, intentFilter);
        return ˋ;
    }

    public int ߵ() {
        return h.ـॱ;
    }

    public void ॱ(Activity activity) {
        super.ॱ(activity);
    }

    public void ᐝ() {
        super.ᐝ();
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ᐝ);
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        this.ᐝʻ = (FrameLayout) viewGroup.findViewById(j.ʼﹳ);
        this.ͺˎ = (PullUpListView) viewGroup.findViewById(j.ˉॱ);
        this.ͺˎ.setNeedFootView(ﹺ());
        this.ͺˎ.setDividerHeight(0);
        this.ˊ = (NoDataView) viewGroup.findViewById(j.ᐟ);
        if (!(this.ॱॱ || this.ﾟ)) {
            if (this.י.ˊॱ() == 0) {
                Logger.ˎ("AppZoneListFragment", "initFragmentView show NoDataView");
                ٴ();
            } else {
                Logger.ˎ("AppZoneListFragment", "initFragmentView hide NoDataView");
                ˊʻ();
            }
        }
        this.ॱॱ = false;
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        this.ﾞ.ˎ(taskFragment, bVar);
        return false;
    }

    private void י() {
        if (this.ͺˎ instanceof AppZoneListView) {
            AppZoneListView appZoneListView = (AppZoneListView) this.ͺˎ;
            if (appZoneListView.ᐝॱ() != 2) {
                appZoneListView.setFooterViewState(2);
                Logger.ˎ("AppZoneListFragment", "loadMoreToFillTheContain fire,request more data from server,pageNum:" + this.ˏ);
                ʿˊ();
            }
        }
    }

    public CardListAdapter ˎ(Context context, cia o_cia) {
        return new CardListAdapter(context, o_cia) {
            public View getView(int i, View view, ViewGroup viewGroup) {
                View view2 = super.getView(i, view, viewGroup);
                if (getCount() == i + 1 && this.provider.ᐝ()) {
                    AppZoneListFragment.this.י();
                }
                return view2;
            }
        };
    }

    public void ˏ(int i, cih o_cih) {
        super.ˏ(i, o_cih);
    }

    protected void ˊʻ() {
        this.ˊ.ˎ();
    }

    protected void ٴ() {
        this.י.ॱॱ();
        this.י.ˊ(false);
        this.ˊ.ˊ();
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
    }

    protected void ʼ(int i) {
    }

    public void ʻ(int i) {
    }
}
